// 封装请求方法
import axios from './axios'

interface Options {
  data?: unknown
  params?: unknown
  headers?: any
}

export default {
  get(url: string, params?: unknown, headers?: unknown): Promise<any> {
    const options: Options = {}
    if (params) {
      options.params = params
    }
    if (headers) {
      options.headers = headers
    }
    return axios.get(url, options)
  },
  post(
    url: string,
    data?: unknown,
    headers?: unknown,
    params?: unknown
  ): Promise<any> {
    const options: Options = {}
    if (headers) {
      options.headers = headers
    }
    if (params) {
      options.params = params
    }
    return axios.post(url, data, options)
  },
  put(url: string, params?: unknown, headers?: unknown): Promise<any> {
    const options: Options = {}
    if (headers) {
      options.headers = headers
    }
    return axios.put(url, params, options)
  },
  delete(url: string, params?: unknown, headers?: unknown): Promise<any> {
    const options: Options = {}
    if (params) {
      options.params = params
    }
    if (headers) {
      options.headers = headers
    }
    return axios.delete(url, options)
  }
}
